Building the Web Services Interface and Client
Moving to a web services interface and client is a somewhat more difficult comparison of ColdFusion and J2EE implementations for one simple reason: J2EE 1.3 (the current released version of J2EE) does not have a standard implementation. What this means is that the process a developer uses to deploy and digest web services varies greatly depending on which application server he/she uses.
Deploying web services. The reality is that most application servers make it relatively simple to deploy existing Java classes as web services. To use JRun as an example (this was the application server I used for deploying both of these applications), a developer simply needs to create a Web Services Deployment Descriptor (WSDD) or JRun Web Service (JWS) file. Both are fairly straightforward XML-based files. The JWS file will be auto-compiled much like a JSP page.
The ColdFusion MX implementation allows developers to deploy functions
within their CFCs as web services by setting the cffunction
tag’s access attribute to "remote".
That’s it.
But in a hybrid application, it is very likely that developers will have mostly Java classes, especially EJB components, that they will want to expose as web services. This makes sense because the J2EE side of the application will manage most of the business logic and data model. As we know, minimizing the areas where you store business logic is ideal.
In this application in particular, it made sense to expose the reserve()
method of the Reservation bean directly. There is no good reason to
expose Reservation.cfc instead—why add overhead? Whereas the CFC
simplified the ColdFusion implementation, it added nothing to the web
service interface.
Conversely, the Trip.cfc would be a prime candidate to expose. This
is because you don’t use the getTripInfo()method
in other applications. That is why you created the CFC instead of using
the JavaBeans component. You must create an additional function, getTrips(),
to return the list of trip information the query on the home.cfm page
does. After doing that, it might be a good idea to also call this function
directly in the home.cfm page to eliminate two areas with code that
executes the same process (the two areas are in home.cfm and the getTrips()
function in Trip.cfc). That way, if you ever need to change the output,
such as add a thumbnail image, you only need to change it in one place.
The web services client. When working with J2EE, it seemed best to replace a GUI-based web services client, originally written in JSP, with ColdFusion. Comparing the two didn’t bring up any issues. In short, the ColdFusion version is simpler due to its tag-based API, which doesn’t require object-oriented programming. Of course, as with JSP, there is more than one way to solve this problem. One could use custom tags, but this would again require importing the tag library—how these different libraries compare to the ColdFusion implementation varies.
Submit feedback on our tutorials, articles, and sample applications.